package com.ruoyi.hr.controller.hr.salaryadmin.salaryinfo;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.salaryadmin.salaryinfo.SalaryInfoPayEmpService;
import com.ruoyi.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 薪资信息(发薪员工)
 */
@Controller
@RequestMapping("/salaryInfo/salaryInfoPayEmp")
public class SalaryInfoPayEmpController extends BaseController {

    @Autowired
    SalaryInfoPayEmpService salaryInfoPayEmpService;

    @Autowired
    AuthorityService authorityService;

    private String prefix = "hr/salaryadmin/salaryinfo/salaryinfopayemp";

    /**
     * 跳转初始化页面
     */
    @GetMapping()
    public String salaryInfoPayEmp() {
        return prefix + "/salaryInfoPayEmp";
    }

    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map map){
        SysUser user = ShiroUtils.getSysUser();
        List<Authority> authorityList = authorityService.getAuthorityUser(user.getUserId().toString());
        int isAdmin = 0;
        if (authorityList.size() == 1) {
            if (authorityList.get(0).getIsAdmin() != null) {
                isAdmin = 1;
            }
        }
        startPage();
        List<Map<String,Object>> list = salaryInfoPayEmpService.findData(map,authorityList,isAdmin);
        return getDataTable(list);
    }

    /**
     * 启动停用福利地区
     *
     * @param map
     */
    @PostMapping("/changeHangUp")
    @ResponseBody
    public AjaxResult changeHangUp(@RequestParam Map map) {
        return toAjax(salaryInfoPayEmpService.changeHangUp(map));
    }

    /**
     * 修改薪资套地区
     */
    @PostMapping("/update")
    @ResponseBody
    public int update(@RequestParam Map map){
        return salaryInfoPayEmpService.update(map);
    }
}
